package com.robot.mvvm.ui.work

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager
import com.alibaba.android.arouter.facade.annotation.Route
import com.robot.base.base.activity.GLBaseActivity
import com.robot.base.configs.AppConstants
import com.robot.mvvm.BR
import com.robot.mvvm.R
import com.robot.mvvm.databinding.AppActivityRepairWorkOrderBinding
import com.robot.mvvm.vm.work.RepairWorkOrderViewModel

/**
 * 报修工单
 */
@Route(path = AppConstants.Router.Main.A_REPAIR_WORK_ORDER)
class RepairWorkOrderActivity :
    GLBaseActivity<AppActivityRepairWorkOrderBinding, RepairWorkOrderViewModel>() {

    private var mTitles = mutableListOf<String>()

    private var fragmentList = mutableListOf<Fragment>()

    override fun initContentView(savedInstanceState: Bundle?): Int =
        R.layout.app_activity_repair_work_order

    override fun initVariableId(): Int = BR.viewModel

    override fun initComponents() {
        addSingleTitleBar(getString(R.string.app_tips_41))
        initViewPager()
    }

    fun initViewPager() {
        mTitles =
            mutableListOf<String>(
                getString(R.string.app_tips_54),
                getString(R.string.app_tips_55),
                getString(R.string.app_tips_56),
                getString(R.string.app_tips_57),
                getString(R.string.app_tips_58),
            )
        fragmentList.add(RepairWorkOrderFragment.newInstance(""))
        fragmentList.add(RepairWorkOrderFragment.newInstance("0"))
        fragmentList.add(RepairWorkOrderFragment.newInstance("1"))
        fragmentList.add(RepairWorkOrderFragment.newInstance("2"))
        fragmentList.add(RepairWorkOrderFragment.newInstance("5"))

        binding.mViewPager.adapter = object : FragmentStatePagerAdapter(supportFragmentManager) {
            override fun getItem(position: Int): Fragment = fragmentList[position]
            override fun getCount(): Int = fragmentList.size
        }
        binding.mViewPager.offscreenPageLimit = fragmentList.size
        binding.tabLayout.setViewPager(binding.mViewPager, mTitles.toTypedArray())
        binding.tabLayout.currentTab = 0

        binding.mViewPager.setOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {

            }

            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {

            }

            override fun onPageSelected(position: Int) {

            }

        })
    }
}